看到一个比较有用的增强 curl 的 function

在 csdn 看到的。。拿来修改了一下。。应该不需要注释了吧,不懂的话就评论吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function xcurl($url,$ref=null,$cookies=null,$post=array(),$ua="Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20110324 Firefox/4.2a1pre",$print=false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
if(!empty($ref)) {
curl_setopt($ch, CURLOPT_REFERER, $ref);
}
if (!empty($cookies)) {
curl_setopt($ch, CURLOPT_COOKIE,$cookies);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(!empty($ua)) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
}
if(count($post) > 0){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$output = curl_exec($ch);
curl_close($ch);
if($print) {
print($output);
} else {
return $output;
}
}